<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Property extends Model
{
    use SoftDeletes;

    protected $fillable = ['province','provincename','region','regionname','area','areaname','town_id','town','metro_id','metro_station_id',
        'title','average','average_unit','openprice','openprice_unit','payment','payment_unit','opentime','hasopen','handtime',
        'hashand','map','longitude','latitude','apartment','feature','featuretxt','salestatus','renovation_id','renovation',
        'address','saleaddress','saletel','presale','thumb','images','status','recommend',
        'mianji','wytype','ghmianji','jztype','zxstatus','proright','hnum','dnum','rongjilv','developers','lvhua','carnum','wycompany','propertyfee','face','design','traffic',
        'school','shopping','hospital','life','recreation','restaurant','wyname',
        'merit','defect','content','seo_title','seo_keywords','seo_description','follow'
    ];

    //对应文章动态
    public function articles()
    {
        return $this->hasMany('App\Models\Article');
    }

    //楼盘下所有的相册
    public function album()
    {
        return $this->hasMany('App\Models\Album');
    }

    //楼盘下所有的户型
    public function apartments()
    {
        return $this->hasMany('App\Models\Apartment');
    }

    public function attribute()
    {
        return $this->belongsToMany('App\Models\Attribute','attribute_properties','property_id')->where('type','property');
    }

    public function getFeaturetxtAttribute($value)
    {
        return json_decode($value);
    }

    public function getImagesAttribute($value)
    {
        return unserialize($value);
    }

    public function getRecommendAttribute($value)
    {
        return explode(',',$value);
    }


}
